#include<bits/stdc++.h>
using namespace std;
int n[100001],l;
int dp[100001];
vector<int> f[100001];
int flag[100001];
bool c[100001];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int q;
    cin>>q;
    while(q--)
    {
        memset(n,0,sizeof(n));
        memset(dp,0,sizeof(dp));
        memset(flag,0,sizeof(flag));
        memset(c,0,sizeof(c));
        for(int i=1;i<=100001;i++)f[i].clear();
        cin>>l;
        for(int i=1;i<=l;i++)
        {
            cin>>n[i];
            if(f[n[i]].size()!=0)
                flag[i]=f[n[i]][f[n[i]].size()-1];
            f[n[i]].push_back(i);
        }
        c[1]=0;
        for(int i=1;i<=l;i++)
        {
            dp[i]=dp[i-1];
            c[i]=c[i-1];
            if(flag[i])
            {
                c[i]=c[flag[i]];
                int sum=dp[flag[i]-1]+n[i];
                if(sum>dp[i])
                {
                    dp[i]=sum;
                    for(int j=flag[i]+1;j<i;j++)
                        c[j]=!c[i];
                }
            }
        }
        int ans=0;
        for(int i=1;i<=l;i++)
            if(c[i]==c[flag[i]]&&flag[i]!=0)ans+=n[i];
        cout<<ans<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
